<script type="text/javascript" >
    jQuery("#adminHeader a[rel^='prettyPhoto']").prettyPhoto({
        theme:'facebook',
        keyboard_shortcuts: false
    });
    stSocialMediaToolbox.sortColumn();
    stSocialMediaToolbox.shortAction();
    stSocialMediaToolboxCustom.switchButton();
    
    function setCmsUrl(appName, userID){
        var data_post = new Array();
        data_post['app'] = appName;
        data_post['userID'] = userID;
        jQuery.prettyPhoto.loadPage('setCmsUrl', data_post);
    }
</script>
<div class="buttonActionContainer" style="left: 168px;">
    <a href="javascript:" class="button add-new-h2 buttonAction" onclick="
        var data_post = new Array();
        data_post['return_action'] = 'appPermission';
        jQuery.prettyPhoto.loadPage('userAddNew', data_post);
       " >
        <?php _e($iconNew, $config['plugin_name'])?>
    </a>
</div>
<div class="w100p bgl">
    <div class="w100p bgr">
        <div class="inner_container">
            <?php //var_dump($results);?>
            <table class="widefat" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stSocialMediaToolbox_st_appperm'); ?>
                    </tr>
                </thead>

                <tbody>
                <?php
                
                if (count($results) > 0) {
                    $tr_class = "";
                    foreach ($results as $result) {
                        if( empty($tr_class) || $tr_class == "class='bg_gray2'"){
                            $tr_class = "class='bg_gray1'";
                        }else{
                            $tr_class = "class='bg_gray2'";
                        }
                        $app_name = explode(',', $result->app_name);
//                        $user_login = get_user_by('id', $result->user_id);                        
                        $user_login = $result->user_login;
//                        $user_data = get_user_by('id', $result->user_id);
//                        if ($user_data && is_array($user_data->wp_capabilities)) {
//                            foreach ($user_data->wp_capabilities as $key => $value) {
//                                $role = $key;
//                            }
//                        }
//                        switch ($role) {
//                            case 'administrator':
//                                $role = 'Master admin';
//                                break;
//                            case 'editor':
//                                $role = 'Client admin';
//                                break;
//                            default:
//                                $role = 'Regular user';
//                                break;
//                        }
//                        $user_parent = get_user_by('id', $result->parent_id);
//                        $user_parent = $user_parent->user_login;
                        if($result->parent_id){
                            $user_meta = get_user_meta($result->parent_id, 'company_info', true);
                        }else{
                            $user_meta = get_user_meta($result->user_id, 'company_info', true);
                        }
                        if($user_login != $config['userAdminName']){
                            echo "<tr id='$result->id' $tr_class >"
                            . "<td>" . $user_login . "</td>"
                            ;
                        
                            if(count($toolboxApp)>0){
                                foreach ($toolboxApp as $key => $value) {

                                    if(!empty($key)){
                                        if(in_array($key, $app_name)){
                                            $status = 'cb-enable';
                                        }else{
                                            $status = 'cb-disable';
                                        }
                                        if($key == 'fbCms'){
                                            $callBackFunction = "setCmsUrl('$key', '{$result->user_id}')";
                                        }else{
                                            $callBackFunction = "";
                                        }
                                        echo "<td>"
                                        . '<div userID="'.$result->user_id.'" callBackFunction="'.$callBackFunction.'" name="'.$key.'" class="' . $status . ' switch_checkbox">'
                                        . '</div>';
                                        if($key == 'coupon')
                                        echo '<span onclick="stSocialMediaToolbox.loadPage(\'app_setting&app='.$key.'&user='.$user_login.'\');" style="cursor:pointer;">&nbsp;(Settings)</span>';
                                        if($key == 'fbCms')
                                        echo '<span onclick="
                                            var data_post = new Array();
                                            data_post[\'app\'] = \''.$key.'\';
                                            data_post[\'userID\'] = \''.$result->user_id.'\';
                                            jQuery.prettyPhoto.loadPage(\'setCmsUrl\', data_post);" style="cursor:pointer;">&nbsp;(set CMS url)</span>';
                                        
                                        echo "</td>"
                                        ;
                                    }

                                }
                            }else{
                                echo "<td>"
                                    . 'none'
                                    . "</td>"
                                    ;
                            }
                            echo "</tr>"
                            ;
                        }
                    }
                }
                ?>
                </tbody>
            </table>
            <div class="page_d">
                <?php echo $pagination?>
                <div class="cl"></div>
            </div>

        </div>
    </div>
</div>